﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using AxWMPLib;

namespace MedusaWMP
{
    public partial class MedusaWMPPlayer : Form
    {
        List<AxWindowsMediaPlayer> players = new List<AxWindowsMediaPlayer>();

        public MedusaWMPPlayer()
        {
            InitializeComponent();

            players.Add(axWindowsMediaPlayer1);
            players.Add(axWindowsMediaPlayer2);
            players.Add(axWindowsMediaPlayer3);
            players.Add(axWindowsMediaPlayer4);
            players.Add(axWindowsMediaPlayer5);
            players.Add(axWindowsMediaPlayer6);

        }
        private void filesListBox_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
            {
                e.Effect = DragDropEffects.All;
            }
        }

        private void filesListBox_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            string whichButton =""; 
            try
            {
                whichButton = ((Button)sender).Name.Substring(((Button)sender).Name.Length - 1);
            }
            catch
            {
                whichButton = ((Panel)sender).Name.Substring(((Panel)sender).Name.Length - 1);
            }
            int whichPlayer = int.Parse(whichButton);
            try
            {
                players[whichPlayer - 1].URL = files[0];
            }
            catch { }
        } 
        private void btn_openFile_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = "Open";
            openFileDialog1.Filter = "All Files|*.*";
            string whichButton = ((Button)sender).Name.Substring(((Button)sender).Name.Length - 1);
            int whichPlayer = int.Parse(whichButton);
            try
            {
                if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    players[whichPlayer - 1].URL = openFileDialog1.FileName;
                }
            }catch{}
        }        

        //Fast hide video on close so not visible while unloading
        private void MedusaWMPPlayer_FormClosing(object sender, FormClosedEventArgs e)
        {
            foreach (AxWindowsMediaPlayer player in players)
            {
                player.close();
                player.Visible = false;
            }
        }
    }
}
